﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using RED_NET_Core.BLL;
using RED_NET_Core.DAL;
using System.Data.SqlClient;
using RED_NET_Core.Helper;
using RED_NET_Core.Entity;


namespace RED_NET.ContentPage
{
    public partial class ClassMemberInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GridView1.Attributes.Add("style", "table-layout:fixed");
        }
        protected void Button1_Click1(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile == false)
            {
            
                //Label5.Text = "请选择要导入的EXCEL表!";

                Response.Write("<script>alert('请选择要导入的EXCEL表！')</script>");
                return;
            }
            string ISxls = System.IO.Path.GetExtension(FileUpload1.FileName).ToString().ToLower();//获取扩展名并转化为String类型并小写
            if (ISxls != ".xls")
            {
                Response.Write("<script>alert('请选择excel表！')</script> ");
                //Label3.Text = " 请选择EXCEL表！";
                return;
            }
            string filename = DateTime.Now.ToString("yyyymmddMMss") + FileUpload1.FileName;//
            string savePath = Server.MapPath("../UpFiles/" + filename);//获取绝对地址（相对地址）相对地址利于移植 !"../"往上一层找到文件夹UPFiles 也就是说filename是属于upfiles
            FileUpload1.SaveAs(savePath); //保存
            Class_BLL ClassMember = new Class_BLL();
            int x;
            int UId = Int32.Parse(Session["USER_ID"].ToString());
            try//批量注册
            {
               x= ClassMember.BatchInsetIntoUser(ClassMember.GetDataSetByExcel(
                   savePath, filename),UId);
               Response.Write("<script>alert('导入成功！')</script> ");
                //Label4.Text = " 导入成功！";
                if (x > 0) Label5.Text = x.ToString() + "同学已经存在";
            }
            catch(Exception ex)
            {
                Response.Write("<script>alert('表格格式错误！请选择正确的excel表重新导入')</script> ");
            }
        }

       /*protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "UpdateStudent")
            {

                int StudentId = Int32.Parse(e.CommandArgument.ToString());
                //根据Id调用删除函数（因为要写更新还要重新弄个页面 挺麻烦的 这样方便。不过你一定要加更新页面的话，就。。。就加呗。 = =。完毕
                //写个删除函数就好 在这里调用
            }
        }*/

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string tUid = txtUid.Text.Trim();
            string tCollege = txtCollege.Text.Trim();
            string tClass = txtClass.Text.Trim();
            string tMajor = txtMajor.Text.Trim();
            string tName = txtName.Text.Trim();
            string tSex = txtSex.Text.Trim();
            string tLongTel = txtLongTel.Text.Trim();
            //string strSQL = " insert into _Student(_Uid,_Class) values(' " + tUid + " ',";
            //strSQL += "'" + tClass + " ', " + Session["USER_ID"].ToString() + ")";
            Class_BLL ClassMember = new Class_BLL();
            if (Session["USER"] != null)
            {
                try
                {
                    Users user = (Users)Session["USER"];
                    ClassMember.BatchInsetIntoUsers1(tUid, tCollege, tClass,
                        tMajor, tName, tSex, tLongTel, user.UserId.ToString());
                }
                catch (Exception ex)
                {
                    //错误记录
                    Users user = (Users)Session["USER"];
                    int User_Id = user.UserId;
                    DateTime time = DateTime.Now;
                    ErrorInfo_BLL.AddErrorInfo(User_Id, ex.Message, time);
                    Response.Redirect("~/ContentPage/Error/PageError.aspx");
                }
            }
        }
     }
}

/*    <asp:GridView ID="GridView1" runat="server"  AllowPaging="True" 
        BackColor="White" BorderColor="#99CCFF" BorderStyle="None" BorderWidth="4px" 
        CellPadding="4" DataSourceID="ObjectDataSource1" 
        Width="90%"  Font-Names="宋体"
        Font-Size="X-Large" Height="30px" PageSize="26" 
        onselectedindexchanged="" onrowcommand="GridView1_RowCommand">
 * */
